package controller

import "fmt"

/**
人民币通货膨胀率
*/
const rate = 0.025

const year = 30

const money = 12 * 3778

const apartment = 670000

func Calc() {
	sum := 0.00

	for i := 1; i <= year; i++ {
		sum += money * calcRate(i)
		fmt.Println(sum)
	}

	//这样的话， 考虑到30年 其实真正需要支付的利息大概是
	interest := sum - apartment
	fmt.Printf("真正需要支付的利息大概是%f\n", interest)

	//那我们再来计算一下67W 30年定期的收益
	calcIncome()
}

func calcIncome() {
	incomeRate := 1.0365
	income := 670000.00
	realIncome := 0.00
	realIncomeSum := 0.00
	for i := 1; i <= 30; i++ {
		income = income*incomeRate - money
		realIncome = income * 0.0365
		if realIncome < 0 {
			realIncome = 0.00
		}
		fmt.Printf("第%d年银行定期收益%f\n", i, realIncome)
		realIncomeSum = realIncomeSum + realIncome

		if income < 0 {
			income = 0.00
		}
		//fmt.Printf("第%d年银行定期收益%f\n",i, income)
	}
	fmt.Printf("总收益%f\n", realIncomeSum)
	//减去本金的纯收益
	//fmt.Printf("减去本金的纯收益%f\n", income-670000.00)
}

/**
计算每年的通过膨胀率
*/
func calcRate(currentYear int) float64 {

	yearRate := 1.00
	for i := 1; i <= currentYear-1; i++ {
		yearRate = yearRate * (1 - rate)
	}
	//fmt.Printf("第 %d 年的利率 %f\n", currentYear, yearRate)
	return yearRate
}
